package com.ojoin.trade.supplyloan_core.web.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.impl.BaseDaoImpl;
import com.ojoin.trade.supplyloan_core.web.dao.TbSlLoanStatDayDao;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlLoanStatDay;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 15-10-22
 * Time: 上午11:41
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class TbSlLoanStatDayDaoImpl extends BaseDaoImpl<TbSlLoanStatDay> implements TbSlLoanStatDayDao {


    @Override
    public void insertTbSlLoanStatDay(TbSlLoanStatDay statdayvo) throws BusinessException {
        String mapMethodName ="insert";
        try{
            this.sqlSessionTemplate.insert(getSqlName(mapMethodName),statdayvo);
        }catch (Exception e) {
            throw new DaoException(String.format("插入商户电商平台日统计结果情况信息表出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
    }

    @Override
    public TbSlLoanStatDay queryTbSlLoanStatDay(int joinid, String date) throws BusinessException {
        HashMap<String,Object> map=new HashMap<String, Object>();
        String methodname="selectByJoinidANDdate";
        map.put("id_of_tb_merchant_user",joinid);
        map.put("stat_date",date);
        try {
            List list = this.sqlSessionTemplate.selectList(getSqlName(methodname),
                    map);
            if (list != null && list.size()>0)
                return (TbSlLoanStatDay) list.get(0);
        } catch (Exception e) {
            throw new DaoException(String.format("查询商户电商平台日统计结果情况信息表出错->出错！语句：%s",
                    getSqlName(methodname)), e);
        }
        return null;
    }

	@Override
	public void deleteTbSlLoanDayByPlatformUserIDAndDate(int platformUserId,
			String statDate) throws BusinessException {
		HashMap<String,Object> map=new HashMap<String, Object>();
        String methodname="deleteTbSlLoanDayByPlatformUserIDAndDate";
        map.put("platformUserId",platformUserId);
        map.put("statDate",statDate);
        try {
            this.sqlSessionTemplate.delete(getSqlName(methodname),
                    map);
        } catch (Exception e) {
            throw new DaoException(String.format("删除商户电商平台日统计结果情况信息表出错->出错！语句：%s",
                    getSqlName(methodname)), e);
        }
	}
}
